import time

from common.base import Base, By


class LoginPage(Base):
    """
    封装的登录操作,继承了Base
    """
    def sent_username(self, username):
        # 输入用户名
        self.find_element((By.NAME, 'username')).send_keys(username)

    def sent_password(self, password):
        # 输入密码
        self.find_element((By.NAME, 'password')).send_keys(password)

    def remember(self):
        # 勾选保存信息
        self.click((By.ID, 'remember'))

    def login_btn(self):
        # 点击登录按键
        self.click((By.CLASS_NAME, 'loginbtn'))


if __name__ == '__main__':
    login = LoginPage('chrome')
    time.sleep(2)
    login.get('https://ecshop.test2.shopex123.com/user.php')

    # 执行测试用例
    # 输入账号
    time.sleep(2)
    login.sent_username('wlyou0518')

    # 输入密码
    time.sleep(2)
    login.sent_password('wlyou0518')

    # 勾选保存信息
    time.sleep(2)
    login.remember()

    # 点击登录按键
    time.sleep(2)
    login.login_btn()

    # 后退
    time.sleep(2)
    login.back()

    # 前进
    time.sleep(2)
    login.forward()

    # 刷新
    time.sleep(2)
    login.refresh()

    login.quit(10)